package holdobject;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class Apple {
    private static long counter;
    private final long id=counter++;
    public long getId(){
        return id;
    }
}
class Orange{

}
class Appleandorange{
    @SuppressWarnings("unchecked")
    public static void main(String[] args) {
        List<Apple> apples=new ArrayList<Apple>();

    ArrayList<Apple> al=new ArrayList<Apple>();//把他理解为自动扩充自身尺寸的数组
    for (int i = 0; i <3 ; i++) {
        al.add(new Apple());//用add插入一个对象
        //al.add(new Orange());
    }

    for (int i = 0; i <al.size() ; i++) {
        System.out.println(al.get(i).getId());
        //((Apple)al.get(i)).getId();//用get访问这些对象
    }
}

}